package com.hand.prantice.ssm.controller;

import com.hand.prantice.ssm.annoction.PermissionAnnoction;
import com.hand.prantice.ssm.domain.Role;
import com.hand.prantice.ssm.domain.User;
import com.hand.prantice.ssm.service.IUserService;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

/**
 * @author 马旭阳
 * @date2019/7/16
 */
@RestController
@RequestMapping(value = "/user")
@PermissionAnnoction(value = true)
public class UserController {
    @Autowired
    private IUserService userService;

    @GetMapping
    @PermissionAnnoction(value = true)
    public List<User> queryAllUser() {

        return userService.queryAllUser();
    }

    @GetMapping(value = "/{id}")
    @PermissionAnnoction(value = true)
    public User queryUser(@PathVariable("id") Long id) {

        return userService.queryUser(id);
    }
    @GetMapping(value = "/role/{id}")
    public List<Role> queryUserRole(@PathVariable("id") Long id) {

        return userService.queryUserRole(id);
    }
    @PutMapping
    public  void insertUser(@RequestBody User user) {

        userService.insertUser(user);
    }
    @PostMapping
    public void updateUser(@RequestBody User user){

        userService.updateUser(user);
    }
    @DeleteMapping
    public void deleteUser(@RequestBody User user) {

        userService.deleteUser(user);
    }
    @GetMapping(value = "/users")
    public List<User> queryUserByIds(@RequestParam("ids") String s) {
        String[] arr=s.split(",");
        List<Long> ids = new ArrayList<Long>();
        for (String str : arr) {
            ids.add(Long.parseLong(str));
        }
       return userService.queryUserByIds(ids);
    }
}
